/**
 * 
 */
package com.rangers.auth.sample.jpa.ctrl;

import java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.rangers.auth.base.service.MenuService;
import com.rangers.auth.sample.jpa.entity.Menu;
import com.rangers.auth.sample.jpa.repo.MenuRepo;

/**
 * 菜单ctrl
 * @version 1.0
 * @author fuhw
 * @date 2017年8月21日 上午10:01:59
 */
@RestController
@RequestMapping("/menus")
public class MenuCtrl {
	
	@Autowired
	private MenuService<Menu, Long, MenuRepo> menuService;

	@GetMapping("/{id}")
	public Menu get(@PathVariable("id") Long id) {
		return menuService.get(id);
	}
	
	@GetMapping
	public List<Menu> list() {
		return menuService.list();
	}

	@PostMapping
	public Menu post(@Valid @RequestBody Menu t) {
		return menuService.create(t);
	}

	@PutMapping
	public Menu put(@Valid @RequestBody Menu t) {
		return menuService.update(t);
	}

	@DeleteMapping("/{id}")
	public void delete(@PathVariable("id") Long id) {
		menuService.delete(id);
	}
}
